// LinkedList.cpp : Defines the entry point for the console application.


#include "stdio.h"
#include "stdlib.h"
#include "string.h"




int permute(char in[], char out[], int used[], int length, int level)
{
	int i;


	
	if(level == length)
		printf("%s\n", out);

	for(i=0; i<length; i++){

		if(used[i])
			continue;

		out[level] = in[i];  //this line fill up next unused letter at THIS recursion level pos always : IMPORTANT
		used[i] = 1;
		permute(in, out, used, length, level+1);
		used[i] = 0;	
		
	}
	

	return 0;
}


int main(int argc, char* argv[])
{
	unsigned int i, l;
	char str[] = "ABC";
	
	l = strlen(str);

	int *used = (int*)malloc(sizeof(int) * l);
	char *out = (char*)malloc(sizeof(char) * (l+1));

	out[l] = '\0';

	for(i=0; i<l; i++)
		used[i] = 0;

	
	permute(str, out, used, l, 0);
		
	return 0;
}

